package com.atguigu.transform;

import com.atguigu.been.WaterSensor;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.ArrayList;

/**
 * 字段中max的值改变 其他的值不改变
 * @author wky
 * @create 2021-07-14-11:11
 */
public class Transform_Max {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment senv = StreamExecutionEnvironment.getExecutionEnvironment();
        senv.setParallelism(1);
//        DataStreamSource<Integer> streamSource = senv.fromElements(1, 2, 3, 4, 5, 7);
//        DataStreamSource<String> streamSource = senv.socketTextStream("hadoop102", 9999);
//        SingleOutputStreamOperator<Integer> map = streamSource.map(new MapFunction<String, Integer>() {
//            @Override
//            public Integer map(String s) throws Exception {
//                return Integer.parseInt(s);
//            }
//        });
   //     KeyedStream<Integer, Integer> keyedStream = map.keyBy(ele -> ele % 2);
        ArrayList<WaterSensor> waterSensors = new ArrayList<>();
        waterSensors.add(new WaterSensor("sensor_1", 1607527992000L, 20));
        waterSensors.add(new WaterSensor("sensor_1", 1607527994000L, 50));
        waterSensors.add(new WaterSensor("sensor_1", 1607527996000L, 40));
        waterSensors.add(new WaterSensor("sensor_2", 1607527993000L, 10));
        waterSensors.add(new WaterSensor("sensor_2", 1607527995000L, 30));
        DataStreamSource<WaterSensor> streamSource = senv.fromCollection(waterSensors);
//        KeyedStream<WaterSensor, String> keyedStream = streamSource.keyBy(WaterSensor::getId);
        KeyedStream<WaterSensor, String> keyedStream = streamSource.keyBy(b -> b.getId());
        keyedStream.max("vc").print("max");
//        keyedStream.sum("vc").print("sum");
//        keyedStream.min("vc").print("min");

        senv.execute();
    }
}
